/**
 * All rights Reserved, Designed By www.tokenmaster.io
 *
 * @Title: MarketMgr.java
 * @Package com.tokenassistant.market
 * @author: 橘狮互联网科技有限公司
 * @date: 2018年6月8日 上午11:36:46
 * @version V1.0
 * @Copyright: 2018 www.tokenmaster.io Inc. All rights reserved.
 * 注意：本内容仅限于橘狮互联网科技有限公司内部传阅，禁止外泄以及用于其他的商业目
 */
package com.tokenmaster.aitrade.market;

import java.util.List;

import org.apache.log4j.Logger;

import com.tokenmaster.aitrade.common.system.IndexConfig;
import com.tokenmaster.aitrade.common.system.KLinePoint;
import com.tokenmaster.aitrade.market.okex.Market_Okex_Future;
import com.tokenmaster.aitrade.market.okex.Market_Okex_Spot;

/**
 * @author buxinyun
 * @ClassName: MarketMgr
 * @Description: 各交易市场集中管理类
 * @date 2018年6月8日 上午11:36:46
 */
public class MarketMgr {

	private Logger logger = Logger.getLogger(this.getClass());

	private static MarketMgr instance = new MarketMgr();

	public static MarketMgr getInstance() {
		return instance;
	}

	// OK 期货行情接口
	private Market_Okex_Future market_Okex_Future = Market_Okex_Future.getInstance();

	// OK 现货行情接口
	private Market_Okex_Spot market_okex_spot = Market_Okex_Spot.getInstance();

	// 火币 现货行情接口
	// private Market_Huobi_Spot market_huobi_spot =
	// Market_Huobi_Spot.getInstance();

	// 币安 现货行情接口
	// private Market_binance_Spot market_binance_spot =
	// Market_binance_Spot.getInstance();

	/**
	 * @param indexConfig
	 * @return
	 * @throws Exception
	 */
	public List<KLinePoint> getKLines(IndexConfig indexConfig) throws Exception {
		logger.info("正在准备获取K线数据：交易所名称" + indexConfig.getMarketName() + ", 币种是：" + indexConfig.getSymbol() + ", 时间类别是："
				+ indexConfig.getTypes_Enum());
		// market_type 用于区分期货和现货
		StringBuffer market_type = new StringBuffer();
		market_type.append(indexConfig.getMarketName());
		if (indexConfig.getTradetype().equals("1")) {
			market_type.append("_future");
		} else if (indexConfig.getTradetype().equals("2")) {
			market_type.append("_spot");
		}

		try {
			if (market_type.toString().equals("okex_future")) {
				return market_Okex_Future.getKLines(indexConfig);
			}
			// else if (market_type.toString().equals("huobi_spot")) {
			// return market_huobi_spot.getKLines(indexConfig);
			// } else if (market_type.toString().equals("okex_spot")) {
			// return market_okex_spot.getKLines(indexConfig);
			// } else if (market_type.toString().equals("binance_spot")) {
			// return market_binance_spot.getKLines(indexConfig);
			// }
		} catch (NullPointerException e) {
			logger.error("获取" + indexConfig.getMarketName() + "K线数据为空，原因：参数或者网络");
		}

		return null;
	}

}
